package cn.shiwei.hr.consumer;

import cn.shiwei.hr.to.SMSTO;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

import static cn.shiwei.hr.constants.MessageConstants.*;

/**
 * @author 1363732197
 */
@Component
@Slf4j
public class MessageConsumer
{

    @RabbitListener(queues = QUEUE_NAME_SMS ,containerFactory = "rabbitListenerContainerFactory")
    public void consumerSMS(@Payload SMSTO smsto, Channel channel, Message message){
            log.info(smsto.toString());
        // TODO 应该sms对接口
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
